package com.hust.together.ui;

import com.hust.togethertest.R;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class MainActivity extends TabActivity {

	private static final String HOME_TAB = "home";
	private static final String FRIEND_TAB = "friend";
	private static final String PARTY_TAB = "party";
	private static final String MSG_TAB = "msg";
	private static final String CFG_TAB = "cfg";
	private TabHost tabHost;

	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		tabHost = this.getTabHost();

		TabSpec homeSpec = tabHost.newTabSpec(HOME_TAB).setIndicator(HOME_TAB)
				.setContent(new Intent(this, HomeActivity.class));
		TabSpec friendSpec = tabHost.newTabSpec(FRIEND_TAB)
				.setIndicator(FRIEND_TAB)
				.setContent(new Intent(this, FriendActivity.class));
		TabSpec partySpec = tabHost.newTabSpec(PARTY_TAB)
				.setIndicator(PARTY_TAB)
				.setContent(new Intent(this, PartyActivity.class));
		TabSpec msgSpec = tabHost.newTabSpec(MSG_TAB).setIndicator(MSG_TAB)
				.setContent(new Intent(this, MessageActivity.class));
		TabSpec cfgSpec = tabHost.newTabSpec(CFG_TAB).setIndicator(CFG_TAB)
				.setContent(new Intent(this, ConfigActivity.class));

		tabHost.addTab(homeSpec);
		tabHost.addTab(friendSpec);
		tabHost.addTab(partySpec);
		tabHost.addTab(msgSpec);
		tabHost.addTab(cfgSpec);

		RadioGroup radioGroup = (RadioGroup) this
				.findViewById(R.id.rg_main_btns);

		radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				// TODO Auto-generated method stub

				switch (checkedId) {
				case R.id.rd_home:
					tabHost.setCurrentTabByTag(HOME_TAB);
					break;

				case R.id.rd_party:
					tabHost.setCurrentTabByTag(PARTY_TAB);
					break;

				case R.id.rd_friend:
					tabHost.setCurrentTabByTag(FRIEND_TAB);
					break;

				case R.id.rd_msg:
					tabHost.setCurrentTabByTag(MSG_TAB);
					break;

				case R.id.rd_cfg:
					tabHost.setCurrentTabByTag(CFG_TAB);
					break;

				default:
					break;
				}

			}
		});
	}

}
